// $('.top-banner').css('height',($(window).width()/2)+'px');
// $('#container').css('height',(window.screen.availHeight-50)+'px');
$('#container').css('height',(document.body.clientHeight-60)+'px');
// console.log("窗口高度："+document.body.clientHeight);
// $("#pagination").css('left',(($(window).width()-40)/2)+"px");
//var tongzhiId = null,gonggaoId=null;
$(function () {
    $.extend({
        "swiperOption":function(f1,f2){
            new Swiper(f1, {
                pagination: f2,
                slidesPerView: 1,
                centeredSlides: true,
                paginationClickable: true,
                loop:true,
                autoplay: 2500,
                autoplayDisableOnInteraction: false,
            });
        },
    });

});
function init(){
    //判断是否有新消息
    var newsflag = server.getCache("newsflag");
    if(newsflag==1){
    $("#newsflag").css("display","block");
    }

    // function initSwiper(){
    //     var mySwiper = new Swiper('.swiper-container', {
    //         speed: 1000,
    //         autoplay: true,
    //         pagination: {
    //             el: '.swiper-pagination',
    //         },
    //         loop: true
    //     });
    //
    // };

    function initCaseSwiper(){
        // var mySwiperBanner = new Swiper ('.swiper-container');
        var mySwiperBanner1 = new Swiper ('.banner1',{
            autoplay:true//设置自动循环播放
        });
        var mySwiperBanner2 = new Swiper ('.banner2');
        // $(".swiper-container").each(function(index){
        //     console.log("swiper-container ["+index+"] is initing......");
        //     $.swiperOption($(this),$(this).find(".swiper-pagination"));
        // });
    };

    //获取banner图片
    server.req('wechat/banner/list6',{},function (res) {
        if(res.code==0){
            server.loadData("#myswiper",res);
        }
    })
    server.req('wechat/teacher/hotTeacher',{},function (res) {

        if(res.code==0){
            res.dataT = res.data;
            server.loadData(".Cteacher-body",res);
        }
    })

    //获取通知公告
    server.req('wechat/notice/getNew',{type:1},function (res) {
        // console.log(res)
       if(res.code!=0||!res.data||res.data.length==0)return;
        res.data.forEach(function(e){
            if(e.title.length>12)
                e.title = e.title.substring(0,12)+'...';
        })
        server.loadData("#tongzhi",res);
        autorun("#tongzhi");
    //    tongzhiId = res.data.id;
    });
    server.req('wechat/notice/getNew',{type:2},function (res) {
        if(res.code!=0||!res.data||res.data.length==0)return;
        res.data.forEach(function(e){
            if(e.title.length>12)
                e.title = e.title.substring(0,12)+'...';
        })

        server.loadData("#gonggao",res);
        autorun("#gonggao");
    });


     function  autorun(ele) {
        //获得当前<
        var $uList = $(ele+" .scroll-box  ");
        var timer = null;
        var i=0;
        console.log($uList[0].clientHeight)
        //触摸清空定时器
        $uList.hover(function() {
                clearInterval(timer);
            },
            function() { //离开启动定时器
                timer = setInterval(function() {
                        scrollList($uList);
                    },
                    2000);
            }).trigger("mouseleave"); //自动触发触摸事件
        // console.log( $uList)
        //滚动动画
        function scrollList(obj) {
            //获得当前<li>的高度
            var scrollHeight = $(".scroll-box .scroll-box-item:first").height();
            //滚动出一个<li>的高度
            if(i>0){
                obj[0].scrollTop = (scrollHeight*(i-1))+(scrollHeight*0.5);
                setTimeout(function () {
                    obj[0].scrollTop = scrollHeight*i
                },300)
            }else{
                obj[0].scrollTop = scrollHeight*i
            }


            i++;
            if(obj[0].children.length<i)i=0;

        }
    }

    //获取服务项目
    server.req('wechat/service/alllist',{inTop:1},function (res) {
        console.log(".........服务分类........");
        console.log(res)
        var data1 = [];
        var data2 = [];
        var serviceList = {};
        if(res.code==0){
            if(res.data.length<9){
                // var data1 = [];
                for(var i=0;i<res.data.length;i++){
                    data1.push(res.data[i]);
                }
                serviceList.data1 = data1;
            }else if(res.data.length<17){
                for(var i=0;i<8;i++){
                    data1.push(res.data[i]);
                }
                for(var i=8;i<res.data.length;i++){
                    data2.push(res.data[i]);
                }
                serviceList.data1 = data1;
                serviceList.data2 = data2;

            }
            console.log(serviceList);


            //server.loadData(".swiper-container",serviceList);
            server.loadData("#servicetypes",serviceList);
            initCaseSwiper();
        }
    });
    //获取热门闪测分类
    function writeHotQuicktestType(typevalues){
        console.log(typevalues);
        var strTypeHtml1="";
        var strTypeHtml2="";
        var strTypeHtml3="";
        typevalues.forEach(function(typeitem,typeindex){
            // console.log("..............1.............");
            if(typeitem){
                if(typeitem.hotPosition==1){
                    strTypeHtml1='<div class="hot-category-left"  onclick="quickAskType('+typeitem.id+')">\n' +
                        '                        <img src="'+typeitem.hotImage+'" />\n' +
                        '                    </div>\n';
                }else if(typeitem.hotPosition==2){
                    strTypeHtml2='                    <div class="hot-category-right">\n' +
                        '                        <div class="hot-category-right-item"  onclick="quickAskType('+typeitem.id+')">\n' +
                        '                            <img src="'+typeitem.hotImage+'" />\n' +
                        '                        </div>\n'
                }else if(typeitem.hotPosition==3){
                    strTypeHtml3='                        <div class="hot-category-right-item"  onclick="quickAskType('+typeitem.id+')">\n' +
                        '                            <img src="'+typeitem.hotImage+'" />\n' +
                        '                        </div>\n' +
                        '                    </div>';
                }

            }
        });
        if(server.isEmpty(strTypeHtml1)){
            strTypeHtml1='<div class="hot-category-left">\n' +
                '                        <img src="img/home/hot1.png" />\n' +
                '                    </div>\n';

        }
        if(server.isEmpty(strTypeHtml2)){
            strTypeHtml2='                    <div class="hot-category-right">\n' +
                '                        <div class="hot-category-right-item">\n' +
                '                            <img src="img/home/hot2.png" />\n' +
                '                        </div>\n';
        }
        if(server.isEmpty(strTypeHtml3)){
            strTypeHtml3= '                        <div class="hot-category-right-item">\n' +
                '                            <img src="img/home/hot3.png" />\n' +
                '                        </div>\n' +
                '                    </div>';
        }
        // console.log(strTypeHtml1);
        // console.log(strTypeHtml2);
        // console.log(strTypeHtml3);
        return strTypeHtml1+strTypeHtml2+strTypeHtml3;
    };
server.req('wechat/quicktestype/hotlist',{},function (res) {
    var strQuickType = "";

    if(res.code==0){
        var data = res.data;
        $(".hot-category").html(writeHotQuicktestType(data));
    }
})
    //获取最热测算
    server.req('wechat/quicktest/hotlist',{},function (res) {

        if(res.code==0){
            server.loadData(".hot-body",res);
        }
    });
//获取知识分享
server.req('wechat/cmsarticle/articleforhome',{ids:"33"},function (res) {
    // console.log("-------articleforhome-------")
    // console.log(res)
    if(res.code==0){
        res.data.forEach(function (cmsItem,cmsIndex) {
            if(cmsItem.title.length>20){
                cmsItem.title=cmsItem.title.substring(0,20)+"..";
            }
        })
        server.loadData("#share",res);
    }
})
}
init();

hideNavigator();
$(document).ready(function() {
    $("#newssize").click(function (e) {
     if(! $("#newchatslist [data-item^=newchats\\.length]").text()){
         $("#newchatslist").hide();
         return ;
     }
       if($("#newchatslist").css("display")=="block"){
           $("#newchatslist").hide();
       }else{
           $("#newchatslist").show();
       }

    })
})
// $("#serviceType1").click(function (e) {
//     server.loadindex("page/teacher/teacher")
// });
function toteachers(serviceid) {
    // console.log("type id = "+serviceid);
    server.loadindex("page/teacher/teacher","serviceId="+serviceid);
}
function tohotteachers() {
    // console.log("type id = "+serviceid);
    server.loadindex("page/askteacher/askteacher");
}
function cmslist(id) {
    server.loadindex('page/cms/cms','cmsCategoryId='+id);
};
//去社区动态
function club() {
    server.loadindex('page/club/club');
}
function developing() {
    pop_up_pos('功能开发中，请耐心等待',null,'320px');
    return;
    // server.loadindex('page/chat/chat');
};
function todetail(teacherid) {
    server.loadindex('page/teacher/teacherdetail/teacherdetail','teachid='+teacherid,true);
};
function toTongzhi(t) {
    server.loadindex('page/home/tongzhi/tongzhi','id='+$(t).attr("data-id"),true);
}
function toGonggao(t) {
    console.log($(t).attr("data-id"))
    server.loadindex('page/home/gonggao/gonggao','id='+$(t).attr("data-id"),true);
}
function moreQuickAsk(){
    server.loadindex('page/quickask/quickask');
}
function quickAskType(typeid) {
    server.loadindex('page/quickask/typelist/typelist','typeid='+typeid);
};
function toQuickAskDetailN(id) {
    server.loadindex('page/quickask/quickaskdetail/quickaskdetail','id='+id,false);

};
function tochatlist() {
    server.loadindex('page/chat/chatlist/chatlist');
}
//开通会员vip
function vipbuy() {
    server.loadindex('page/user/vipbuy/vipbuy');
};
//联系我们
function tocontactus() {
    server.loadindex('page/user/contactus/contactus');
};
//去CMS详情页
function articledetail(articleid,dataid){
    server.loadindex('page/cms/cmsdetail/cmsdetail','articleid='+articleid+'&dataid='+dataid);
};
mqttmsg.shownewCathsList();